﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.SharpZipLib.Zip.Compression;

namespace WoWConnecter
{
    /// <summary>
    /// Wrapper for ICSharpCode.SharpZipLib.
    /// </summary>
    public static class Compression
    {
        /// <summary>
        /// Performs deflate compression on the given data.
        /// </summary>
        /// <param name="input">the data to compress</param>
        /// <param name="output">the compressed data</param>
        public static void CompressZLib(byte[] input, byte[] output, int compressionLevel, out int deflatedLength)
        {
            Deflater item = new Deflater(compressionLevel);

            item.SetInput(input, 0, input.Length);
            item.Finish();
            deflatedLength = item.Deflate(output, 0, output.Length);
        }

        /// <summary>
        /// Performs inflate decompression on the given data.
        /// </summary>
        /// <param name="input">the data to decompress</param>
        /// <param name="output">the decompressed data</param>
        public static void DecompressZLib(byte[] input, byte[] output)
        {
            Inflater item = new Inflater();

            item.SetInput(input, 0, input.Length);
            item.Inflate(output, 0, output.Length);
        }
    }
}
